package com.genius.util.Common;

import com.genius.util.Exception.Status;
import com.genius.util.Exception.illuminatorStatus;

public class Result<T> {
    private String code;
    private String msg;
    private T data;

    public Result(){

    }

    public Result(T data){
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setData(T data) {
        this.data = data;
    }

    private static <T> Result<T> success(Status status,Result result){
        result.setCode(status.statusCode);
        result.setMsg(status.statusName);
        return result;
    }

    public static Result success(){
        Result result = new Result();
        success(illuminatorStatus.Success,result);
        return result;
    }

    public static <T> Result<T> success(T data){
        Result<T> result = new Result<>(data);
        success(illuminatorStatus.Success,result);
        return result;
    }

    public static <T> Result<T> success(T data,Status status){
        Result<T> result = new Result<>(data);
        success(status,result);
        return result;
    }

    public static Result error(String code,String msg){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }


    public static Result error(Status error){
        Result result = new Result();
        result.setCode(error.statusCode);
        result.setMsg(error.statusName);
        return result;
    }


}
